" 常量折叠优化演示脚本
" 展示优化器如何识别和优化常量表达式

echo "=== 常量折叠优化演示 ==="

" 这些表达式在编译时会被优化
echo "基本算术优化:"
let result1 = 2 + 3 * 4        " 将被折叠为 14
echo "result1 =" result1

let result2 = (10 - 5) / 2      " 将被折叠为 2.5
echo "result2 =" result2

let result3 = -5 + 3           " 将被折叠为 -2
echo "result3 =" result3

" 复合表达式优化
echo "复合表达式优化:"
let complex1 = 1 + 2 + 3 + 4     " 可以被折叠为 10
echo "complex1 =" complex1

let complex2 = (2 * 3) + (4 * 5) " 可以被折叠为 26
echo "complex2 =" complex2

" 比较和逻辑表达式
echo "逻辑表达式优化:"
let logic1 = (5 > 3) && (2 < 4)    " 可以被折叠为 true AND true = true
echo "logic1 =" logic1

let logic2 = (10 == 10) || (5 == 3)  " 可以被折叠为 true OR false = true
echo "logic2 =" logic2

" 字符串操作
echo "字符串常量:"
let str_result = len("Hello") + len("World") " 可以被折叠为 5 + 5 = 10
echo "str_result =" str_result

echo "=== 演示完成 ==="
echo "注意: 在优化器完整实现后，这些常量表达式将在编译时计算，"
echo "而不是在运行时计算，从而提高执行性能。"